<script>

function ajoutville(){
	$("#ajaxEnregistrerVille").show();
}


$(document).ready(function() {
	//////
	$("#ajaxEnregistrerVille").hide();
	$("#ajaxEnregistrerMotdePasse").hide();
	$("#ajaxEnregistrerMotdePasseClinic").hide();
	var $pays = $('#pays');
	var $ville = $('#ville');
	
	$pays.on('change', function() {
		var val = $(this).val(); 
		if(val != '') {
			$ville.empty(); // on vide la liste 
			$.ajax({
			url: '<?php echo base_url();?>index.php/dn/selectville',
			data: 'id_pays='+ val, // on envoie $_GET['id_etat_type']
			dataType: 'json',
			success: function(json) {
				$.each(json, function(index, value) {
					$ville.append('<option value="'+ index +'">'+  value +'</option>');
				});
			}
			});
		}
	});

	$("#enregistrerVille").on('click', function() {
		var $pays = $('#pays').val();
		var $nom_ville_ajout = $('#nom_ville_ajout').val();
		var $url = "<?php echo base_url();?>index.php/dn/ajoutVille";
		if ($nom_ville_ajout !=""){
			$.post($url, {pays : $pays, nom_ville_ajout : $nom_ville_ajout},				
				function(data){
					$ville.empty(); // on vide la liste 
					$.ajax({
					url: '<?php echo base_url();?>index.php/dn/selectville',
					data: 'id_pays='+ $pays, // on envoie $_GET['id_etat_type']
					dataType: 'json',
					success: function(json) {
						$.each(json, function(index, value) {
							$ville.append('<option value="'+ index +'">'+  value +'</option>');
						});
					}
					});
					alert ("Ville enregistré");
					$("#ajaxEnregistrerVille").hide();
				}
			);
		}
		else {
			alert("Champ vide !");
		}
	});
	
	$("#Enregistrer_mdp_modif").on('click', function() {
		var $logged_in = $('#logged_in').val();
		var $conf_modif = $('#conf_modif').val();
		var $mdp_modif = $('#mdp_modif').val();
		var $idid = $('#idid').val();
		var $mdp_actuel_patient = $('#mdp_actuel_patient').val();
		var $mdp_patient_base = $('#mdp_patient_base').val();
		var $url = "<?php echo base_url();?>index.php/dn/modifMdp";
		if ($conf_modif !="" && $mdp_modif!="" && $conf_modif==$mdp_modif && $mdp_actuel_patient == $mdp_patient_base){
			$.post($url, {mdp : $mdp_modif, idid : $idid, logged_in: $logged_in},				
				function(data){
					alert ("Mot de passe modifié");
					$("#ajaxEnregistrerMotdePasse").hide();
				}
			);
		}
		else {
			alert("Erreur!");
		}
	});

	$("#Enregistrer_mdp_modif_Clinic").on('click', function() {
		var $logged_in_clinic = $('#logged_in').val();
		var $conf_modif_clinic = $('#conf_modif_Clinic').val();
		var $mdp_modif_clinic = $('#mdp_modif_Clinic').val();
		var $mdp_actuel_Clinic = $('#mdp_actuel_Clinic').val();
		var $mdp_base = $('#mdp_base').val();
		var $idid = $('#idid').val();
		var $url = "<?php echo base_url();?>index.php/dn/modifMdp";
		if ($conf_modif_clinic !="" && $mdp_modif_clinic!="" && $conf_modif_clinic==$mdp_modif_clinic && $mdp_actuel_Clinic == $mdp_base){
			$.post($url, {mdp : $mdp_modif_clinic, idid : $idid, logged_in: $logged_in_clinic},				
				function(data){
					alert ("Mot de passe modifié");
					$("#ajaxEnregistrerMotdePasseClinic").hide();
				}
			);
		}
		else {
			alert("Erreur!");
		}
	});

	$("#ajoutelogo").on('click', function() {
		var $logo = $('#logo').val();
		var $id_clinique = $('#id_clinique').val();
		var $url = "<?php echo base_url();?>index.php/dn/ajoutLogoGalImage";
		if ($logo != ""){
				$.post($url, {logo : $logo, id_clinique : $id_clinique});
				$('#ajoutelogo').hide();
				$('#logo').hide();
				$('#btnModifLogo').show();
			}
			else {
				alert("Le logo ne doit pas être vide !");
		}
	});
	
	$("#ajouteImgPpl").on('click', function() {
		var $image_principale = $('#image_principale').val();
		var $id_clinique = $('#id_clinique').val();
		var $url = "<?php echo base_url();?>index.php/dn/ajoutImgPpl";
		if ($image_principale != ""){
				$.post($url, {image_principale : $image_principale, id_clinique : $id_clinique});
				$('#ajouteImgPpl').hide();
				$('#image_principale').hide();
				$('#btnModifImgPpl').show();
			}
			else {
				alert("L'image principale ne doit pas être vide !");
		}
	});
	
	$("#ajoutegalerie").on('click', function() {
		var $nbreImageGallerie = $('#nbreImageGallerie').val();
		var $id_clinique = $('#id_clinique').val();
		var $url = "<?php echo base_url();?>index.php/dn/ajoutgalerie";
		var $imageupload0 = $("#imageupload0").val();
		var $imageupload1 = $("#imageupload1").val();
		var $imageupload2 = $("#imageupload2").val();
		var $imageupload3 = $("#imageupload3").val();
		var $imageupload4 = $("#imageupload4").val();
		var $imageupload5 = $("#imageupload5").val();
		var $imageupload6 = $("#imageupload6").val();
		var $imageupload7 = $("#imageupload7").val();		
		var $imageupload8 = $("#imageupload8").val();
		var $imageupload9 = $("#imageupload9").val();
		if ($id_clinique != ""){
				$.post($url, {id_clinique : $id_clinique, nbreImageGallerie : $nbreImageGallerie, imageupload0: $imageupload0, imageupload1: $imageupload1, imageupload2: $imageupload2, imageupload3: $imageupload3, imageupload4: $imageupload4, imageupload5: $imageupload5, imageupload6: $imageupload6, imageupload7: $imageupload7, imageupload8: $imageupload8, imageupload9: $imageupload9});
				$('#ajoutegalerie').hide();
				$('#imagee').hide();
				$('#ajouteImage').hide();
				$('#btnModifGalImages').show();
		}
		else {
			alert("Erreur!");
		}
	});
	
	$("#ajoutePhotoSoins").on('click', function() {
		var $nbreImageGallerie1 = $('#nbreImageGallerie1').val();
		var $id_clinique = $('#id_clinique').val();
		var $url = "<?php echo base_url();?>index.php/dn/ajoutPhotoSoins";
		var $imageuploads0 = $("#imageuploads0").val();
		var $imageuploads1 = $("#imageuploads1").val();
		var $imageuploads2 = $("#imageuploads2").val();
		var $imageuploads3 = $("#imageuploads3").val();
		var $imageuploads4 = $("#imageuploads4").val();
		var $imageuploads5 = $("#imageuploads5").val();
		var $imageuploads6 = $("#imageuploads6").val();
		var $imageuploads7 = $("#imageuploads7").val();		
		var $imageuploads8 = $("#imageuploads8").val();
		var $imageuploads9 = $("#imageuploads9").val();
		if ($id_clinique != ""){
				$.post($url, {id_clinique : $id_clinique, nbreImageGallerie1 : $nbreImageGallerie1,imageuploads0: $imageuploads0, imageuploads1: $imageuploads1, imageuploads2: $imageuploads2, imageuploads3: $imageuploads3, imageuploads4: $imageuploads4, imageuploads5: $imageuploads5, imageuploads6: $imageuploads6, imageuploads7: $imageuploads7, imageuploads8: $imageuploads8, imageuploads9: $imageuploads9});
				$('#ajoutePhotoSoins').hide();
				$('#imagee1').hide();
				$('#ajouteImage1').hide();
				$('#btnModifPhotoSoins').show();
		}else{
			alert("Erreur!");
		}
	});
	$("#changerMdp").on('click', function() {
		$("#ajaxEnregistrerMotdePasse").show();
	});

	$("#changerMdpClinic").on('click', function() {
		$("#ajaxEnregistrerMotdePasseClinic").show();
	});	
	$("#Annuler_mdp_modif_Clinic").on('click', function() {
		$("#ajaxEnregistrerMotdePasseClinic").hide();
	});
	$("#Annuler_mdp_modif_patient").on('click', function() {
		$("#ajaxEnregistrerMotdePasse").hide();
	});	
	
	 $($("#antecedent"), "input[type='checkbox']" ).click(function(){ 
	        if(this.checked == false){
	            $("#ajaxAntecedentsMedicaux").show();
	        }
		else {
			$("#ajaxAntecedentsMedicaux").hide();
		}
	});

});
</script>